import axios from "axios"
export default function ajax(url = "", params = {}, method = "get") {
	let promise = null
	return new Promise((resolve, reject) => {
		if (method == "get") {
			let paramsStr = ""
			Object.keys(params).forEach(key => {
				paramsStr += key + "=" + params[key] + "&"
			})
			if (paramsStr != "") {
				paramsStr = paramsStr.slice(0, -1)
			}
			url += "?" + paramsStr
			promise = axios.get(url)
		} else if (method == "post") {
			promise = axios.post(url, params)
		}
		promise.then(res => {
			resolve(res.data)
		}).catch(err => {
			reject(err)
		})
	})
}